<?php
/**
 * The page that generates the HTML to test the various
 * CSS layouts.
 *
 * @copyright RFI, 2008-02-08
 */

require_once $_SERVER['DOCUMENT_ROOT'] . '/set-current-values.inc.php';

/*
 * ----------------------------------------
 * Save some stuff in the session var.
 * ----------------------------------------
 */

/*
 * Save the current URL in the session so that we can return to it.
 */

if (!isset($_SESSION['previous_layout_urls'])) {
	$_SESSION['previous_layout_urls'] = array();
}

array_unshift(
	$_SESSION['previous_layout_urls'],
	array(
		'url' => $_SERVER['REQUEST_URI'],
		'time' => date('c')
	)
);

/*
 * ----------------------------------------
 * Generate various strings that will be used in the output.
 * ----------------------------------------
 */

/*
 * Generate the URL for the style sheet.
 */

$css_generator_url = '/css-generator.php';

#$css_generator_url .= 'navigation_float=' . $current_form_values['navigation_float'];
#
#$css_generator_url .= '&';
#
#$css_generator_url .= 'content_float=' . $current_form_values['content_float'];

$first = TRUE;
foreach ($current_values as $k => $v) {
	if ($first) {
		$css_generator_url .= '?';
		
		$first = FALSE;
	} else {
		$css_generator_url .= '&';		
	}
	
	$css_generator_url .= "$k=$v";
}

/*
 * Generate the navigation list.
 */

$div_navigation = "<div id=\"navigation\">\n";

$div_navigation .= "<h2>Navigation</h2>\n";

$div_navigation .= "<ul>\n";

$div_navigation .= "<li><a href=\"/\">Return to form</a></li>\n";
$div_navigation .= "<li><a href=\"$css_generator_url\">Layout CSS</a></li>\n";

if (
	preg_match('/^\d+$/', $current_values['navigation_extra_links'])
	&&
	($current_values['navigation_extra_links'] > 0)
) {
	for ($i = 0; $i < $current_values['navigation_extra_links']; $i++) {
		$div_navigation .= "<li><a href=\"#\">A Link</a></li>\n";
	}
} else {
	$div_content .= "<p class=\"error\">Please set a positive number for how many  extra links there should be in the navigation bar!</p>\n";
}

$div_navigation .= "</ul>\n";

$div_navigation .= "</div>\n";

/*
 * Generate the text for the content.
 */

$div_content = "<div id=\"content\">\n";

$div_content .= "<h2>Content</h2>\n";

if (
	preg_match('/^\d+$/', $current_values['content_paragraphs'])
	&&
	($current_values['content_paragraphs'] > 0)
) {
	for ($i = 0; $i < $current_values['content_paragraphs']; $i++) {
		$div_content .= <<<LIP
<p>
	Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
	tempor incididunt ut labore et dolore magna aliqua.
	Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
	ut aliquip ex ea commodo consequat.
	Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
	dolore eu fugiat nulla pariatur.
	Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
	deserunt mollit anim id est laborum.
</p>

LIP;

	}
} else {
	$div_content .= "<p class=\"error\">Please set a positive number for how many paragraphs there should be in the content!</p>\n";
}

$div_content .= "</div>\n";

/*
 * ----------------------------------------
 * Write out the HTML
 * ----------------------------------------
 */

echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . "\n";

?>
<html>
	<head>
		<title>RFI's CSS Layout Generator</title>
		<link rel="stylesheet" href="/basics.css" type="text/css" />
		<link rel="stylesheet" href="<?php echo $css_generator_url; ?>" type="text/css" />
	</head>
	<body>
		<div id="container">
			<div id="header">
				<h1><a href="/">RFI's CSS Layout Generator</a></h1>
			</div>
			<div id="central">
<?php
if ($current_values['navigation_before_content'] == 1) {
	echo $div_navigation;
	echo $div_content;
} else {
	echo $div_content;
	echo $div_navigation;
}
?>
			</div>
			<div id="footer">
				&copy; 2008 <a href="http://impey.info/">Robert Impey</a>
			</div>
		</div>
		<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
		<script type="text/javascript">
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
		</script>
		<script type="text/javascript">
		var pageTracker = _gat._getTracker("UA-1939164-3");
		pageTracker._initData();
		pageTracker._trackPageview();
		</script>
	</body>
</html>